﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WastedMechanics
{
    public class Music
    {
        public FMOD.Sound FmodSound;
        public FMOD.Channel FmodChannel;
        public string FileName;

        public Music(string fileName)
        {
            FileName = Engine.GetResourcePath(fileName);
        }

        public void Load()
        {
            Engine.SoundManager.FmodSystem.createSound(FileName, (FMOD.MODE._2D | FMOD.MODE.HARDWARE | FMOD.MODE.CREATESTREAM), ref FmodSound);
            FmodSound.setMode(FMOD.MODE.LOOP_NORMAL);
        }

        public void Play()
        {
            Engine.SoundManager.FmodSystem.playSound(FMOD.CHANNELINDEX.FREE, FmodSound, false, ref FmodChannel);
            
            FmodChannel.setPaused(false);
        }

        public void Pause()
        {
            FmodChannel.setPaused(true);            
        }

        public void Resume()
        {
            FmodChannel.setPaused(false);
        }

        public void Unload()
        {
            if (FmodSound != null)
            {
                FmodSound.release();
                FmodSound = null;
            }
            FmodChannel = null;
        }
    }
}
